<%@page contentType="text/html" language="java" import="com.compuvest.web.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/tld/leftmenu.tld" prefix="lmenu" %>
<%@ taglib uri="/WEB-INF/tld/items.tld" prefix="itemstld" %>
<%@ taglib uri="/WEB-INF/tld/navigation.tld" prefix="navigation" %>
<%@ taglib uri="/WEB-INF/tld/advertblock.tld" prefix="advert" %>
<%@ taglib uri="/WEB-INF/tld/head.tld" prefix="head" %>
<%@ taglib uri="/WEB-INF/tld/bottom.tld" prefix="bottom" %>

<jsp:useBean id="sb" class="MySQL" scope="application"/>
<jsp:useBean id="advertArray" class="AdvertArray" scope="application"/>
<jsp:useBean id="basket" class="Basket" scope="session"/>
<%!
    public static final int PREF_SIZE = 7;
%>
<%
    String thisURL = "ItemsNewarrival.jsp";
    String pageName = "New Arrival Stock";

    int pageNo = advertArray.getInt(request.getParameter("pg"), 0);
    int catID = advertArray.getInt(request.getParameter("cid"), 0);
    int scatID = advertArray.getInt(request.getParameter("sid"), 0);
    int sortID = advertArray.getInt(request.getParameter("srt"), 1);

    int lowPrice = advertArray.getFloatToInt(request.getParameter("lop"), 0);
    int hiPrice  = advertArray.getFloatToInt(request.getParameter("hip"), 0);

    // preference
    StringBuilder popUrl = new StringBuilder(200);
    StringBuilder hidden = new StringBuilder(200); // for price range
    java.util.Map<Integer,String> popData = null;
    if(scatID != 0) {
	popData = new java.util.HashMap(PREF_SIZE);
	for(int position = 0; position < PREF_SIZE; position++) {

	    String pop = advertArray.getString(request.getParameter("p" + position), "");
	    if(pop.length() == 0) continue;

	    popData.put(position, pop);

            hidden.append("<input type=hidden name=p").append(position).append(" value=").append(pop).append(" />");
	    popUrl.append("&p").append(position).append("=").append(java.net.URLEncoder.encode(pop,"UTF-8"));
	}
    }

    Items items = sb.getItemsNewArrival(catID, scatID, sortID, popData, lowPrice, hiPrice, pageNo);

    session.setAttribute("thisURL", thisURL);
    session.setAttribute("pageName", pageName);
%>
<html>
<%@include file="/incl/head.html" %>

<body>

<table style='height:100%;'>

<tr height=100>
 <td colspan=3 valign=top>

<head:show
 pageName='<%= pageName %>'
/>

 </td>
</tr>

<tr valign=top>
 <td style="width:200px;">
<form name=Preference action='<%= thisURL %>' method=POST>
<input type=hidden name=pg value=<%= pageNo %> />
<input type=hidden name=cid value=<%= catID %> />
<input type=hidden name=sid value=<%= scatID %> />
<input type=hidden name=srt value=<%= sortID %> />
<%= hidden.toString() %>

<lmenu:show
 pageName='<%= pageName %>'
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 lowPrice='<%= lowPrice %>'
 hiPrice='<%= hiPrice %>'
 pageUrl='<%= new StringBuilder(100).append(thisURL).append("?pg=0&srt=").append(sortID).toString() %>'
 items='<%= items %>'
 popUrl='<%= popUrl.toString() %>'
 popData='<%= popData %>'
/>

</form>
 </td>

 <td align=center>
   <%-- begin Items content --%>

<navigation:show
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 lowPrice='<%= lowPrice %>'
 hiPrice='<%= hiPrice %>'
 items='<%= items %>'
 popUrl='<%= popUrl.toString() %>'
 popData='<%= popData %>'
 />


<form name=SortForm action='<%= thisURL %>' method=POST>
<input type=hidden name=pg value=0 />
<input type=hidden name=cid value=<%= catID %> />
<input type=hidden name=sid value=<%= scatID %> />
<input type=hidden name=lop value=<%= lowPrice %> />
<input type=hidden name=hip value=<%= hiPrice %> />
<%= hidden.toString() %>

<itemstld:show
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 pageNo='<%= pageNo %>'
 pageUrl='<%= new StringBuilder(100).append(thisURL).append("?cid=").append(catID).append("&sid=").append(scatID).append("&lop=").append(lowPrice).append("&hip=").append(hiPrice).append(popUrl).toString() %>'
 reseller='<%= basket.getReseller() %>'
 items='<%= items %>'
 sortID='<%= sortID %>'
/>
</form>

  <%-- end Items content --%>
 </td>

 <td style="width:120px;">

<div style='background-color:white;text-align:center;font:bold 10px arial;color:#870101;'>
<div onclick="location.href='<%= application.getInitParameter("AdvertServer") %>excel/Wholesale Prices.xls'">
<fieldset style='cursor:pointer;'>
<img src='<%= application.getInitParameter("AdvertServer") %>excel/icon.png' style='float:left;'/>Wholesale Inventory<br/>Download Now
</fieldset>
</div>
</div>

 </td>
</tr>

<tr height=35>
 <td colspan=3>

<bottom:show />

 </td>
</tr>

</table>

</body>
<%@ include file="./incl/tracking.incl" %>
</html>
